package org.game.module.event.listener;

import org.constant.EventConditionKey;
import org.constant.EventConditionType;
import org.constant.EventType;
import org.game.db.bean.MonthCard;
import org.game.db.bean.Player;
import org.game.plugin.event.GameEvent;
import org.game.plugin.event.GameEventListener;
import org.game.plugin.event.GameEventStack;
import org.game.plugin.event.GameEventType;

import com.sojoys.artifact.tools.ToolMap;

import java.util.Date;

/**
 * @author : DengYing
 * @CreateDate : 2018年1月11日 下午2:59:44
 * @Description ：动作事件
 */
@GameEventType(EventType.OTHER_EVENT)
public class OtherEventListenner implements GameEventListener {

	@Override
	public void onEvent(GameEvent event) {
		GameEventStack eventStack = event.peek();
		switch (eventStack.getConditionType()) {
		case EventConditionType.COMPOUND: {
			if (checkTriggerType(event.getIn(), eventStack.getConditionType())){
				eventStack.changeProgress(1);
			}
			break;
		}
		case EventConditionType.SUMMON: {
			if (checkTriggerType(event.getIn(), eventStack.getConditionType())){
				eventStack.changeProgress(ToolMap.getInt(EventConditionKey.CARD_COUNT, event.getIn()));
			}
			break;
		}
		case EventConditionType.BUY_RESOURCE: {
			if (checkTriggerType(event.getIn(), eventStack.getConditionType())){
				boolean bool = verify_eq(EventConditionKey.RESOURCE_CID, event.getIn(), eventStack.getParams());
				if (bool) {
					eventStack.changeProgress(1);
				}
			}
			break;
		}
		case EventConditionType.STORE_BUY: {
			if (checkTriggerType(event.getIn(), eventStack.getConditionType())){
				boolean bool = verify_eq(EventConditionKey.COMMODITY_CID, event.getIn(), eventStack.getParams());
				bool &= verify_eq(EventConditionKey.STORE_CID, event.getIn(), eventStack.getParams());
				if (bool) {
					eventStack.changeProgress(1);
				}
			}
			break;
		}
		case EventConditionType.GAIN_MONTH_CARD: {
			if (checkTriggerType(event.getIn(), eventStack.getConditionType())){
				Player player = event.getPlayer();
				MonthCard mc = player.getMonthCardsFkPlayerId();
				Date now = new Date();
				if (mc != null && now.getTime() < mc.getGainLimitDate().getTime()){
					eventStack.changeProgress(1);
				}
			}
			break;
		}
        case EventConditionType.SMALL_GAME: {
            if (checkTriggerType(event.getIn(), eventStack.getConditionType())){
                boolean bool = verify_eq(EventConditionKey.SUB_TYPE, event.getIn(), eventStack.getParams());
                if (bool) {
                    eventStack.changeProgress(1);
                }
            }
            break;
        }

		}
	}

	@Override
	public void initEventCondition(Player player, GameEventStack eventStack) {
	}
}
